package com.zyz.I_多线程.线程通信;

/**
 * @author: vick
 * @Date: 2025/3/24
 * @Description:
 * @version: 1.0
 */
public class Demo1 implements Runnable{
    int i = 1;
    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                notify();
                if (i <= 100) {
                    System.out.println(Thread.currentThread().getName() + ": " + i++);
                }else {
                    break;
                }
                try {
                    wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    public static void main(String[] args) {
        Demo1 demo1 = new Demo1();
        new Thread(demo1, "子线程1").start();
        new Thread(demo1, "子线程2").start();
    }
}
